import axios from "axios";
const http = axios.create({
  baseURL: "/api",
  timeout: 5000,
});
const cookie = localStorage.getItem("COOKIE");
http.interceptors.response.use(
  (res: any) => {
    if (res.config.url == "/login/status") {
      return {
        code: res.data.data.code,
        data: res.data,
      };
    }
    if (res.status === 200 && res.data.code) {
      return {
        code: res.data.code,
        data: res.data,
      };
    }
  },
  (err) => {
    return Promise.reject(err);
  }
);
export const getRequest = (url: string, params = {}) => {
  if (cookie) {
    return http.get(url, {
      params: { ...params, cookie: encodeURIComponent(cookie) },
    });
  } else {
    return http.get(url, { params: { ...params } });
  }
};
